package servlet;

import com.alibaba.fastjson.JSONArray;
import service.ExportExlService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;

@WebServlet(name = "exportExlServlet", value = "/exportExlServlet")
public class ExportExlServlet extends HttpServlet {

    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=UTF-8");

        ExportExlService exportExlService=new ExportExlService();
        JSONArray jsonArray=null;
         if (req.getParameter("moshi").equals("勾选模式")){
             try {
                 jsonArray=exportExlService.ExportExlDaoOrIntList(JSONArray.parseArray(req.getParameter("data")));
             } catch (SQLException throwables) {
                 throwables.printStackTrace();
             }
         }

         if (req.getParameter("moshi").equals("下拉筛选模式")){
             String name=req.getParameter("name");
             String banji=req.getParameter("banji");
             String startDate=req.getParameter("startDate");
             String endDate=req.getParameter("endDate");
             int mark=Integer.parseInt(req.getParameter("mark"));

             try {
                  jsonArray=exportExlService.ExportExlDaoOrNameOrBanjiOrDateTime( name,  banji,  startDate,  endDate, mark);
             } catch (SQLException throwables) {
                 throwables.printStackTrace();
             }

         }
        PrintWriter out = resp.getWriter();
        out.print(jsonArray);
        out.flush();
        out.close();




    }

    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

    }

}
